package com.zx.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zx.sys.domain.New;
import com.zx.sys.mapper.NewMapper;
import com.zx.sys.service.NewService;
import com.zx.sys.utils.DataGridView;
import com.zx.sys.vo.NewVo;

@Service
public class NewServiceImpl implements NewService {
	
	@Autowired
	private NewMapper newMapper;

	@Override
	public DataGridView queryAllNew(NewVo newVo) {
		Page<Object> page = PageHelper.startPage(newVo.getPage(), newVo.getLimit());
		List<New> list = newMapper.queryAllNews(newVo);
		return new DataGridView(page.getTotal(),list);
	}

	@Override
	public void addNew(NewVo newVo) {
		newMapper.insertSelective(newVo);
	}

	@Override
	public void updateNew(NewVo newVo) {
		newMapper.updateByPrimaryKeySelective(newVo);
	}

	@Override
	public void deleteNew(Integer id) {
		newMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void deleteBatchNew(Integer[] ids) {
		for (Integer id : ids) {
			newMapper.deleteByPrimaryKey(id);
		}
	}

	@Override
	public New queryNewById(Integer id) {
		return newMapper.selectByPrimaryKey(id);
	}

}
